<?php 
class AdEmployment extends Ad
{
	public $AdEmploymentId;
	public $IsFullTime;
	public $EmploymentType;
	public $CountryPart;
	public $DateStart;
	public $DateDue;
	public $Diploma;
	
	public function getAdEmploymentId() { return intval($this->AdEmploymentId); }
	public function getIsFullTime() { return intval($this->IsFullTime); }
	public function getEmploymentType() { return intval($this->EmploymentType); }
	public function getCountryPart() { return intval($this->CountryPart); }
	public function getDiploma() { return intval($this->Diploma); }
	public function getDateStart($format = '') 
	{ 
		if($format != '')
		{ return self::formatDateTime($this->DateStart, $format); }
		else
		{ return $this->DateStart; }
	}
	public function getDateDue($format = '') 
	{ 
		if($format != '')
		{ return self::formatDateTime($this->DateDue, $format); }
		else
		{ return $this->DateDue; }
	}
	
	public function getUseIsNew() { return 0; }
	public function getUsePrice() { return 0; }
	public function getUseBrand() { return 6; }
	public function getUseYear() { return 0; }
	public function getUseModel() { return 0; }
	
	public function setAdEmploymentId($val) { $this->AdEmploymentId=intval($val); }
	public function setIsFullTime($val) { $this->IsFullTime=intval($val); }
	public function setEmploymentType($val) { $this->EmploymentType=intval($val); }
	public function setCountryPart($val) { $this->CountryPart=intval($val); }
	public function setDiploma($val) { $this->Diploma=intval($val); }
	public function setDateStart($val) { $this->DateStart=self::formatDateTime($val, 'd.m.Y'); }
	public function setDateDue($val) { $this->DateDue=self::formatDateTime($val, 'd.m.Y'); }
	
	function update()
	{
		if((self::getId() > 0) && (self::getDataChanged()))
		{
			global $user;
			if(($user->getId() == self::getUserId()) || ($user->getLevel() > 4) || (defined('RUN_IMPORT')))
			{
				self::updateAd();
				
				if(self::getAdEmploymentId() > 0)
				{
					$sql  = 'UPDATE '.DB_PERFIX.'am_ads_employment SET ';
					$sql .= '`AdEmploymentId`='.self::getId().', ';
					$sql .= '`IsFullTime`='.self::getIsFullTime().', ';
					$sql .= '`EmploymentType`='.self::getEmploymentType().', ';
					$sql .= '`Diploma`='.self::getDiploma().', ';
					$sql .= '`CountryPart`='.self::getCountryPart().', ';
					$sql .= '`DateStart`="'.self::getDateStart('Y-m-d').'", ';
					$sql .= '`DateDue`="'.self::getDateDue('Y-m-d').'" ';
					$sql .= ' WHERE AdEmploymentId='.self::getId().' LIMIT 1;';
					mysql_query($sql);
				}
				else
				{
					$insert  = '`AdEmploymentId`';
					$values  = self::getId();
					$insert .= ', `IsFullTime`';
					$values .= ', '.self::getIsFullTime();
					$insert .= ', `EmploymentType`';
					$values .= ', '.self::getEmploymentType();
					$insert .= ', `Diploma`';
					$values .= ', '.self::getDiploma();
					$insert .= ', `CountryPart`';
					$values .= ', '.self::getCountryPart();
					$insert .= ', `DateStart`';
					$values .= ', "'.self::getDateStart().'"';
					$insert .= ', `DateDue`';
					$values .= ', "'.self::getDateDue().'" ';
					$sql  = 'INSERT INTO '.DB_PERFIX.'am_ads_employment ('.$insert.') '; 
					$sql .= 'VALUES ('.$values.');';
					$result = mysql_query($sql);
				}
				//echo $sql;
			}
		}
	}
}
?>